﻿<%@ WebHandler Language="C#" Class="deleteSetProd" %>

using System;
using System.Web;
using System.Data;

using AMCBO;
using AMCOBJ;

public class deleteSetProd : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        //context.Response.Write("Hello World");
        if (!string.IsNullOrEmpty(context.Request.QueryString["id"]))
        {
            settings prodSettings = new settings();
            settingsObj settObjs = new settingsObj();
            settObjs.ProdID = Convert.ToInt32(context.Request.QueryString["id"]);
            int x = prodSettings.deleteProduct(settObjs);
            if (x == 0)
            {
                loadCurData(context);
            }
            else
            {
                context.Response.Write("n");
            }
        }
        
    }
    public void loadCurData(HttpContext pContext)
    {
        settings prodSettings = new settings();
        DataTable dt = new DataTable();
        string retJSON = string.Empty;
        dt = prodSettings.getProductsExisting();
        if (dt.Rows.Count > 0)
        {
            retJSON = "[";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                retJSON += "{\"id\":\"" + dt.Rows[i]["id"] +
                    "\",\"prodname\":\"" + dt.Rows[i]["fulProdNme"] +
                    "\"},";
            }
            if (retJSON[retJSON.Length - 1] == ',')
            {
                retJSON = retJSON.Substring(0, retJSON.Length - 1);
            }
            retJSON += "]";
            pContext.Response.Write(retJSON);
        }
        else
        {
            pContext.Response.Write("l");
        }
    }
    public bool IsReusable {
        get {
            return false;
        }
    }

}